package com.jiaozi.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jiaozi.core.annotation.Log;
import com.jiaozi.core.security.utils.SecurityUtil;
import com.jiaozi.core.table.JzTable;
import com.jiaozi.base.utils.bean.R;
import com.jiaozi.system.pojo.param.sys.user.UserPageParam;
import com.jiaozi.system.pojo.param.sys.user.UserPasswordParam;
import com.jiaozi.system.pojo.param.sys.user.UserSaveParam;
import com.jiaozi.system.pojo.param.sys.user.UserUpdateParam;
import com.jiaozi.system.pojo.vo.sys.user.UserInfoVO;
import com.jiaozi.system.pojo.vo.sys.user.UserPageVO;
import com.jiaozi.system.service.SysUserService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 系统-用户(SysUser)表控制层
 *
 * @author jiaozi
 * @since 2024-08-15 14:02:36
 */
@Tag(name = "用户管理")
@RestController
@RequestMapping("/sysUser")
public class SysUserController {
    /**
     * 服务对象
     */
    @Autowired
    private SysUserService sysUserService;

    @Operation(summary = "用户初始化",description = "用户初始化")
    @GetMapping("/info")
    @ApiOperationSupport(order = 1)
    @Log("用户初始化")
    public  R<JzTable> info(){
        JzTable jzTable=new JzTable(UserPageVO.class);
        jzTable.setRefreshBotton(true);
        jzTable.setQueryCriteriaBotton(true);
        jzTable.setColumnsBotton(true);
        jzTable.setPage(true);
        jzTable.setDataUrl("/sysUser/page/");
        return R.ok(jzTable);
    }
    @Operation(summary = "分页查询列表",description = "分页查询列表")
    @GetMapping("/page/{pageNum}/{pageSize}")
    @ApiOperationSupport(order = 1)
    @Log("分页查询用户信息")
    public R<IPage<UserPageVO>> userPage(@Parameter(name ="pageNum" ,description = "页码", required = true)
                                             @PathVariable(value = "pageNum") Long pageNum,
                                         @Parameter(name ="pageSize" ,description = "页条数", required = true)
                                             @PathVariable(value = "pageSize") Long pageSize,
                                         UserPageParam param
                                         ){
        return sysUserService.userPage(pageNum, pageSize, param);
    }

    @Operation(summary = "查询用户信息",description = "查询用户信息")
    @GetMapping("/{userId}")
    @ApiOperationSupport(order = 2)
    @Log("查询用户信息")
    public R<UserInfoVO> userQuery(@Parameter(name ="userId" ,description = "用户编号", required = true)
                            @PathVariable(value = "userId") String userId ){
        return sysUserService.userQuery(userId);
    }


    @Operation(summary = "新增用户信息",description = "新增用户信息")
    @PostMapping("/")
    @ApiOperationSupport(order = 3)
    @Log("新增用户信息")
    public R userSave(@RequestBody UserSaveParam userSaveParam){
        return sysUserService.userSave(userSaveParam);
    }


    @Operation(summary = "修改用户信息",description = "修改用户信息")
    @PutMapping("/{userId}")
    @ApiOperationSupport(order = 4)
    @Log("修改用户信息")
    public R userUpdate(@Parameter(name ="userId" ,description = "用户编号", required = true)
                            @PathVariable(value = "userId") String userId,@RequestBody UserUpdateParam userUpdateParam){
        return sysUserService.userUpdate(userUpdateParam,userId);
    }


    @Operation(summary = "修改用户密码",description = "修改用户密码")
    @PutMapping("/userPassword")
    @ApiOperationSupport(order = 5)
    @Log("修改用户密码")
    public R userPassword(@RequestBody UserPasswordParam userPasswordParam){
        return sysUserService.userPassword(userPasswordParam, SecurityUtil.getLoginUser().getLoginUser().getUserId());
    }




    @Operation(summary = "删除用户信息",description = "删除用户信息")
    @DeleteMapping("/{userId}")
    @ApiOperationSupport(order = 6)
    @Log("删除用户信息")
    public R userDelete(@Parameter(name ="userId" ,description = "用户编号", required = true)
                        @PathVariable(value = "userId") String userId ){
        return sysUserService.userDelete(userId);
    }


    @Operation(summary = "重置用户密码",description = "重置用户密码")
    @PutMapping("/resettingPwd/{userId}")
    @ApiOperationSupport(order = 6)
    @Log("重置用户密码")
    public R resettingPwd(@Parameter(name ="userId" ,description = "用户编号", required = true)
                        @PathVariable(value = "userId") String userId ){
        return sysUserService.resettingPwd(userId);
    }



}

